package com.xyy.saas.payment.adpater.pingxx.service;

import java.lang.reflect.InvocationTargetException;
import java.lang.reflect.Method;
import java.util.Map;
import java.util.concurrent.ConcurrentHashMap;

/**
 * @Author: wuqiongda
 * @Date: 2020/3/19 9:50
 */
public class PingxxAdpaterService {

    private ConcurrentHashMap<String, Method> concurrentHashMap = new ConcurrentHashMap();

    public Map<String, String> wxqr(Map<String, String> params, Map<String, String> extra){
        extra.put("product_id", params.get("productId"));
        return extra;
    }
    public Map<String, String> wxh5(Map<String, String> params, Map<String, String> extra){
        return extra;
    }


    public Map<String, String> wxpub(Map<String, String> params, Map<String, String> extra){
        extra.put("open_id", params.get("openId"));
        return extra;
    }

    public Map<String, String> wxmini(Map<String, String> params, Map<String, String> extra){
        extra.put("open_id", params.get("openId"));
        return extra;
    }

    public Map<String, String> wxapp(Map<String, String> params, Map<String, String> extra) {
        return extra;
    }

    public Map<String, String> unionPaypc(Map<String, String> params, Map<String, String> extra){
        extra.put("result_url", params.get("resultUrl"));
        return extra;
    }
    public Map<String, String> alipayqr(Map<String, String> params, Map<String, String> extra){
        return extra;
    }

    public Map<String, String> alipayapp(Map<String, String> params, Map<String, String> extra){
        return extra;
    }

    public Map<String, String> alipayh5(Map<String, String> params, Map<String, String> extra){
        extra.put("success_url", params.get("successUrl"));
        return extra;
    }

    public Map<String, String> alipaymini(Map<String, String> params, Map<String, String> extra){
        extra.put("buyer_user_id", params.get("buyerId"));
        return extra;
    }

    private Class pingxxAdpaterServiceClass = Class.forName("com.xyy.saas.payment.adpater.pingxx.service.PingxxAdpaterService");

    public Map<String, String> invoker(String methodName, Map<String, Object> params, Map<String, String> extra) throws NoSuchMethodException, InvocationTargetException, IllegalAccessException {
        Method method = concurrentHashMap.get(methodName);
        if (method==null){
            method = pingxxAdpaterServiceClass.getMethod(methodName, Map.class, Map.class);
            concurrentHashMap.put(methodName, method);
        }
        return (Map<String, String>) method.invoke(getInstance(), params, extra);
    }
    private PingxxAdpaterService() throws ClassNotFoundException {};

    public static PingxxAdpaterService getInstance() {
        return MyPingxxAdpaterService.instance;
    }

    /**
     * 内部类
     */
    private static class MyPingxxAdpaterService{
        private static PingxxAdpaterService instance;

        static {
            try {
                instance = new PingxxAdpaterService();
            } catch (ClassNotFoundException e) {
            }
        }
    }
}
